package io;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class ReadStringDemo01 {
    public static void main(String[] args) throws IOException {
        //1.构建文件输入流对象
        //File file = new File("./f1.txt");
        //long size = file.length();
        //FileInputStream fis = new FileInputStream(file);
        FileInputStream fis = new FileInputStream("./f1.txt");
        //2.读取文件内容（将数据读取到数组中）
        //byte[] data = new byte[(int)size];
        byte[] data = new byte[fis.available()]; //fis.available()获取流中有效字节数
        int len = fis.read(data);
        //3.将字节数组内容转换为字符串并输出
        String str = new String(data,0,len);
        System.out.println(str);
        //4.关闭流
        fis.close();
    }
}
